<template>
<view class="container">
  <!--账户余额信息start  -->
  <view class="account_balance_info" v-if="clientNo&&clientNo!='zhihuishangwu'">
    <text class="balance_text">账户{{properties.alias_yue||'余额'}}</text>
    <text class="account_num">￥{{moneyAmount}}</text>
    <view v-if="fxDetail&&fxDetail.fxSetting.sendProfitType!=1" class="tixian_btn" :style="'background:linear-gradient(116deg,' + (setting.platformSetting.secondColor||'#fff') + ' 0%,' + (setting.platformSetting.defaultColor||'#ff0000') + ' 100%);'" @click.stop="userRecharge">
      <text>提现</text>
    </view>
  </view>
  <!--账户余额信息end  -->
  <!--账户余额列表start  -->
  <view class="account_balance_record">
    <view class="account_balance_list_title">
      <image class="record_icon" src="https://image1.sansancloud.com/xianhua/2020_1/8/15/57/13_184.jpg?x-oss-process=style/preview_120"></image>
      <text>{{properties.alias_yongjin||'佣金'}}记录</text>
    </view>
    <view class="account_balance_list">
      <block v-if="!!Data">
        <view class="account_balance_item" v-for="(pay, index) in Data" :key="index">
          <view class="account_balance_top">
            <text class="tixian_account">{{pay.requestAmount}}{{properties.alias_yongjin||'佣金'}}</text>
            <view class="tixian_state">
              <text class="derection" v-if="pay.requestStatus == 0">审核中...</text>
              <text class="derection" v-if="pay.requestStatus == 2">审核失败</text>
              <text class="derection" v-if="pay.requestStatus == 1&&pay.fangkuanStatus == 0">未发放</text>
              <text class="derection" v-if="pay.requestStatus == 1&&pay.fangkuanStatus == 1">已发放</text>
            </view>
            <text class="tixian_time">{{pay.addTime}}</text>
          </view>
        </view>
      </block>
      <block v-else>
        <view class="no_tixian_list">
          <text>主人，您还没有{{properties.alias_yongjin||'佣金'}}记录哦~！</text>
        </view>
      </block>
    </view>
  </view>
  <!--账户余额列表end  -->
</view>
</template>

<script>

export default {
  data() {
    return {
      Data: [],
      moneyAmount: 0,
      listPage: {
        page: 1,
        pageSize: 0,
        totalSize: 0,
        curpage: 1
      },
      reflesh: 0,
      setting: "",
      properties: "",
      clientNo:'',
      fxDetail:null,
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_fx_detailFun();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      setting: getApp().globalData.setting,
      properties: getApp().globalData.properties,
      clientNo:  getApp().globalData.clientNo
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      wx.setNavigationBarTitle({
        title: "使用"+(getApp().globalData.properties.alias_yongjin||'佣金')+"记录"
      });
    if (this.reflesh == 1) {
      this.Data = [];
      this.listPage.page = 1;
      this.get_fx_detailFun();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.Data = [];
    this.listPage.page = 1;
    this.get_fx_detailFun();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;

    if (that.listPage.totalSize > that.listPage.curPage * that.listPage.pageSize) {
      that.listPage.page++;
      this.getData();
    }
  },
  methods: {
    userRecharge: function () {
      this.setData({
        reflesh: 1
      });
      this.tolinkUrl('req_tixian_section.html')
      // wx.navigateTo({
      //   url: "/pages/req_tixian_section/index"
      // });
    },
    //获取推广中心，查看是否有资格
    get_fx_detailFun: function (setting) {
      console.log('-------推广中心--------');
      var customIndex = getApp().globalData.AddClientUrl("/wx_get_fx_data.html");
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===get_fx_detail===", res);
          if (res.data.errcode == '0') {
            let fxDetail = res.data.relateObj;
            that.setData({
              fxDetail: fxDetail
            });
            that.getData()
            that.getAmoutMoney();
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    /* 获取数据 */
    getData: function () {
      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      var getParams = {};
      getParams.page = this.listPage.page;
      var customIndex = getApp().globalData.AddClientUrl("/get_tixian_list.html", getParams);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          that.listPage.pageSize = res.data.pageSize;
          that.listPage.curPage = res.data.curPage;
          that.listPage.totalSize = res.data.totalSize;
          let dataArr = that.Data;
          dataArr = dataArr.concat(res.data.result);

          if (!res.data.result || res.data.result.length == 0) {
            that.setData({
              Data: null
            });
          } else {
            //that.setData({ moneyAmount: dataArr[0].afterAmount })
            that.setData({
              Data: dataArr
            });
          }
        },
        complete: function (res) {}
      });
    },

    getAmoutMoney() {
      if (!getApp().globalData.checkIfLogin()) {
        return;
      }
      getApp().globalData.showToastLoading('loading', true);
      var customIndex = getApp().globalData.AddClientUrl("/get_fx_yongjin_list.html");
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          let dataArr = res.data.result;

          if (!res.data.result || res.data.result.length == 0) {//that.setData({ Data: null })
          } else {
            that.setData({
              moneyAmount: dataArr[0].afterAmount
            }); //that.setData({ Data: dataArr })
          }
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    /* 组件事件集合 */
    tolinkUrl: function (e) {
	  console.log("tolinkUrl",e)
      let linkUrl = e.currentTarget?e.currentTarget.dataset.link:e;
      getApp().globalData.linkEvent(linkUrl);
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>